package com.ruoyi.web.controller.operationAdministration;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.ruoyi.operationAdministration.vo.EquipmentBookVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.operationAdministration.domain.OperationEquipmentBook;
import com.ruoyi.operationAdministration.service.IOperationEquipmentBookService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备基础台账Controller
 *
 * @author lth
 * @date 2023-12-21
 */
@RestController
@RequestMapping("/operationAdministration/book")
public class OperationEquipmentBookController extends BaseController
{
    @Autowired
    private IOperationEquipmentBookService equipmentBookService;

    /**
     * 查询设备基础台账列表
     */
    @PreAuthorize("@ss.hasPermi('operationAdministration:book:list')")
    @GetMapping("/list")
    public TableDataInfo list(OperationEquipmentBook equipmentBook)
    {
        startPage();
        List<OperationEquipmentBook> list = equipmentBookService.selectEquipmentBookList(equipmentBook);
        return getDataTable(list);
    }

    /**
     * 导出设备基础台账列表
     */
    @PreAuthorize("@ss.hasPermi('operationAdministration:book:export')")
    @Log(title = "设备基础台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OperationEquipmentBook equipmentBook)
    {
        List<OperationEquipmentBook> list = equipmentBookService.selectEquipmentBookList(equipmentBook);
        ExcelUtil<OperationEquipmentBook> util = new ExcelUtil<OperationEquipmentBook>(OperationEquipmentBook.class);
        util.exportExcel(response, list, "设备基础台账数据");
    }

    /**
     * 获取设备基础台账详细信息
     */
    @PreAuthorize("@ss.hasPermi('operationAdministration:book:query')")
    @GetMapping(value = "/{equipmentId}")
    public AjaxResult getInfo(@PathVariable("equipmentId") String equipmentId)
    {
        return success(equipmentBookService.selectEquipmentBookByEquipmentId(equipmentId));
    }

    /**
     * 新增设备基础台账
     */
    @PreAuthorize("@ss.hasPermi('operationAdministration:book:add')")
    @Log(title = "设备基础台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperationEquipmentBook equipmentBook)
    {
        return toAjax(equipmentBookService.insertEquipmentBook(equipmentBook));
    }

    /**
     * 修改设备基础台账
     */
    @PreAuthorize("@ss.hasPermi('operationAdministration:book:edit')")
    @Log(title = "设备基础台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperationEquipmentBook equipmentBook)
    {
        return toAjax(equipmentBookService.updateEquipmentBook(equipmentBook));
    }

    /**
     * 删除设备基础台账
     */
    @PreAuthorize("@ss.hasPermi('operationAdministration:book:remove')")
    @Log(title = "设备基础台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipmentIds}")
    public AjaxResult remove(@PathVariable String[] equipmentIds)
    {
        return toAjax(equipmentBookService.deleteEquipmentBookByEquipmentIds(equipmentIds));
    }

    /**
     * 设备基础台账列表
     */
    @PreAuthorize("@ss.hasPermi('operationAdministration:book:list')")
    @GetMapping("/getEquipmentBookList")
    public TableDataInfo getEquipmentBookList(@RequestBody EquipmentBookVo vo)
    {
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        List<OperationEquipmentBook> list = equipmentBookService.getEquipmentBookList(vo);
        return getDataTable(list);
    }
}
